﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 自定义：BUFF持有组件
/// </summary>
public class BuffBox : MonoBehaviour
{
    public Image buffImage;
    public Text buffName;
    public Text buffLeftTime;
    public Text buffStack;

    [HideInInspector]
    public TimedBuff buff;
    private Color buffShowColor = Color.white;
    private Color buffHideColor = Color.clear;

    //public delegate void buffEndHandler(int index);
    //public event buffEndHandler buffEndEvent;

    private void Start()
    {
        buff = null;
    }

    private void Update()
    {
        //根据buff持续时间执行

        if (buff != null)
        {
            if (buff.Duration > 0)
            {
                buffLeftTime.text = buff.Duration.ToString("00");
            }
            else
            {
                CleanData();
            }
        }

    }

    //注册一个新BUFF
    public void RegisterBuffInfo()
    {
        buffImage.color = buffShowColor;
        buffName.text = buff.Buff.bName;
        buffImage.sprite = buff.Buff.bSprite;
        buffStack.text = buff.EffectStacks.ToString();
    }

    public void CleanData()
    {
        buffImage.color = buffHideColor;
        buffName.text = null;
        buffImage.sprite = null;
        buffStack.text = null;
        buffLeftTime.text = null;
        buff = null;
    }
}
